/*******************************************************************************
03_01: Make Table X1: Effect of source country characteristics on non-market work 
	when controling for gender composition of children

Replication code for "Culture and gender allocation of tasks: source country 
	characteristics and the division of non-market work among US immigrants" in
	Review of Economics of the Household

Authors: Francine Blau, Lawrence Kahn, Matthew Comey, Amanda Eng, Pamela 
	Meyerhofer, and Alexander Willen
	
Date: 10/16/2020

*******************************************************************************/


/*******************************************************************************

I. Preliminaries

*******************************************************************************/

***A. Erase existing output if necessary
cap erase "$tables/Table_X1_Panel_A.xls"
cap erase "$tables/Table_X1_Panel_A.txt"
cap erase "$tables/Table_X1_Panel_B.xls"
cap erase "$tables/Table_X1_Panel_B.txt"
cap erase "$tables/Table_X1_Panel_C.xls"
cap erase "$tables/Table_X1_Panel_C.txt"
cap erase "$tables/Table_X1_Panel_D.xls"
cap erase "$tables/Table_X1_Panel_D.txt"


***B. Set control variables
local fe i.day i.month i.year i.state

*First Generation Control Variables
local im_controls age age2 hsdi scol cold RACE2 RACE3 RACE4 RACE5 yrsusa1 yrsusa2 cohort70_79 cohort80_89 cohort90_99 cohort00_09 cohort10_17

local im_part_controls part_age part_age2 part_hsdi part_scol part_cold part_RACE2 part_RACE3 part_RACE4 part_RACE5 part_immig part_secondgen part_yrsusa1 part_yrsusa2 part_cohort70_79 part_cohort80_89 part_cohort90_99 part_cohort00_09 part_cohort10_17

*Secong Generation Control Variables
local sg_controls age age2 hsdi scol cold RACE2 RACE3 RACE4 RACE5

local sg_part_controls part_age part_age2 part_hsdi part_scol part_cold part_RACE2 part_RACE3 part_RACE4 part_RACE5 part_immig part_secondgen part_yrsusa1 part_yrsusa2 part_cohort70_79 part_cohort80_89 part_cohort90_99 part_cohort00_09 part_cohort10_17

/*******************************************************************************

II. Run Regressions

*******************************************************************************/

local maintit "Table X1: Effect of source country characteristics on non-market work when controling for gender composition of children"

**Loop through table panels
foreach panel in A B C D {
	
	*Set sample restrictions and labels
	preserve
	
	if "`panel'" == "A" {
	    di "*****Regressing Immigrant Women with Children*****"
		
		drop if hh_numownkids== 0
		keep if youngc<18 
		keep if female == 1 & immig==1
		
		local tabtit "`maintit', Panel A. Immigrant Women with Children"
		
		local main_controls `im_controls' `im_part_controls' `fe'
		local source_vars GGI GDP_000 fertility
		local cluster cluster(bpl)
		}
	else if "`panel'" == "B" {
	    di "*****Regressing Immigrant Men with Children*****"
		
		drop if hh_numownkids== 0
		keep if youngc<18 
		keep if female == 0 & immig==1
		
		local tabtit "`maintit', Panel B. Immigrant Men with Children"
		
		local main_controls `im_controls' `im_part_controls' `fe'
		local source_vars GGI GDP_000 fertility
		local cluster cluster(bpl)
		}
	else if "`panel'" == "C" {
	    di "*****Regressing 2nd-Gen Immigrant Women with Children*****"
		
		drop if hh_numownkids== 0
		keep if youngc<18 
		keep if female == 1 & secondgen==1
		
		local tabtit "`maintit', Panel C. 2nd-Gen Immigrant Women with Children"
		
		local main_controls `sg_controls' `sg_part_controls' `fe'
		local source_vars parent_GGI parent_GDP_000 parent_fertility
		local cluster cluster(parent_bpl)
		}
	else if "`panel'" == "D" {
	    di "*****Regressing 2nd-Gen Immigrant Men with Children*****"
		
		drop if hh_numownkids== 0
		keep if youngc<18 
		keep if female == 0 & secondgen==1
		
		local tabtit "`maintit', Panel D. 2nd-Gen Immigrant Men with Children"
		
		local main_controls `sg_controls' `sg_part_controls' `fe'
		local source_vars parent_GGI parent_GDP_000 parent_fertility
		local cluster cluster(parent_bpl)
		}


	**Loop through non-market work variables
	foreach var in $nmw $hwork $ccare { 
		
		if "`var'" == "$nmw" {
			local coltit "Total Non-Market Work"
			}
		else if "`var'" == "$hwork" {
			local coltit "Housework"
			}
		else if "`var'" == "$ccare" {
			local coltit "Childcare"
			}
			
		*Main specification (but now display children coefficients)
		reg `var' `source_vars' young_children middle_children old_children `main_controls' [aw=newwt], robust `cluster'
		quietly summ `var' [aw=newwt] if e(sample)==1   
		outreg2 using "$tables/Table_X1_Panel_`panel'.xls", keep(`source_vars' young_children middle_children old_children) append ctitle(`coltit') addstat(Mean, r(mean))  label title("`tabtit'") nocons
		
		*Split by gender
		reg `var' `source_vars' young_girls middle_girls old_girls young_boys middle_boys old_boys `main_controls' [aw=newwt], robust `cluster'
		quietly summ `var' [aw=newwt] if e(sample)==1   
		outreg2 using "$tables/Table_X1_Panel_`panel'.xls", keep(`source_vars' young_girls middle_girls old_girls young_boys middle_boys old_boys) append ctitle(`coltit') addstat(Mean, r(mean))  label title("`tabtit'") nocons
		
		*Testing boy/girl equivalence
		display "Test Young Boy = Young Girl"
		test young_girls=young_boys
		display "Test Middle Boy = Middle Girl"
		test middle_girls=middle_boys
		display "Test Old Boy = Old Girl"
		test old_girls=old_boys
		
		display "Accumulated Test"
		qui test young_girls=young_boys
		qui test middle_girls=middle_boys, acc
		test old_girls=old_boys, acc
		
		}
		
	restore
	
	}
	
	
***Erase text files
cap erase "$tables/Table_X1_Panel_A.txt"
cap erase "$tables/Table_X1_Panel_B.txt"
cap erase "$tables/Table_X1_Panel_C.txt"
cap erase "$tables/Table_X1_Panel_D.txt"
